#coding=utf-8
#@Time:2019\10\15 0015 15:49
#@Author:希哥
#@File:views.py
from django.shortcuts import render
from django.http.response import JsonResponse
import sys

reload(sys)
sys.setdefaultencoding("utf8")

'''
	测试技术平台首页
'''

def sql_index(request):
	return render(request, 'sqltest.html')

'''
	更改用户状态为普通用户
'''
def changeusertype(request):
	new_username= request.GET.get('username')
	from ApiTest import changeUserType
	return render(request, 'test_result.html', {'testmsg': changeUserType.changeType(new_username)})

'''
	清除用户的订单和行程
'''
def clear(request):
	new_username = request.GET.get('username')
	new_type = request.GET.get('type')
	from ApiTest import changeUserType
	return render(request, 'test_result.html', {'testmsg': changeUserType.clear(new_username,new_type)})

#随机生成身份证号码
def idcard(request):
	from ApiTest import id_card
	return render(request, 'test_result.html', {'testmsg':id_card.idcard_generator()[0]})

#修改凭证/行程/预约时间至昨日
def changeTime(request):
	new_order_id = request.GET.get('order_id')
	new_type = request.GET.get('type')
	from ApiTest import changeUserType
	return render(request, 'test_result.html', {'testmsg': changeUserType.changeTime(new_order_id,new_type)})

'''
	新增身份证+姓名，返回json格式数据
'''
def idcard_json(request):
	from ApiTest import id_card
	name = id_card.idcard_generator()[1]
	idcard = id_card.idcard_generator()[2]
	print name,idcard
	data = {
        'name': name,
        'id_card': idcard,
    }
	return JsonResponse(data)

'''
	修复OTA订单退款
'''
def fix_ota(request):
	from ApiTest import fix_otaOrder
	new_order_no = request.GET.get('order_no')
	return render(request, 'test_result.html', {'testmsg': fix_otaOrder.fix(new_order_no)})

'''
	修复异常订单
'''
def fix_order(request):
	from ApiTest import fix_order
	new_order_no = request.GET.get('order_no')
	return render(request, 'test_result.html', {'testmsg': fix_order.fix(new_order_no)})

'''
	作废凭证
'''
def delete_certificate(request):
	from ApiTest import fix_order
	new_order_no = request.GET.get('order_no')
	return render(request, 'test_result.html', {'testmsg': fix_order.delete_certificate(new_order_no)})